package com.ruoyi.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.equipment.EquipmentCheckPlan;
import com.ruoyi.system.domain.equipment.EquipmentFighting;
import com.ruoyi.system.service.equipment.IEquipmentFightingService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 消防设施Controller
 * 
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/equipment/fighting")
public class EquipmentFightingController extends BaseController
{
    @Autowired
    private IEquipmentFightingService equipmentFightingService;

    /**
     * 查询消防设施列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:fighting:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentFighting equipmentFighting)
    {
        startPage();
        List<EquipmentFighting> list = equipmentFightingService.selectEquipmentFightingList(equipmentFighting);
        return getDataTable(list);
    }

    /**
     * 导出消防设施列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:fighting:export')")
    @Log(title = "消防设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentFighting equipmentFighting)
    {
        List<EquipmentFighting> list = equipmentFightingService.selectEquipmentFightingList(equipmentFighting);
        ExcelUtil<EquipmentFighting> util = new ExcelUtil<EquipmentFighting>(EquipmentFighting.class);
        util.exportExcel(response, list, "消防设施数据");
    }

    /**
     * 获取消防设施详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:fighting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentFightingService.selectEquipmentFightingById(id));
    }

    /**
     * 新增消防设施
     */
    @PreAuthorize("@ss.hasPermi('equipment:fighting:add')")
    @Log(title = "消防设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentFighting equipmentFighting)
    {
        return toAjax(equipmentFightingService.insertEquipmentFighting(equipmentFighting));
    }

    /**
     * 修改消防设施
     */
    @PreAuthorize("@ss.hasPermi('equipment:fighting:edit')")
    @Log(title = "消防设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentFighting equipmentFighting)
    {
        return toAjax(equipmentFightingService.updateEquipmentFighting(equipmentFighting));
    }

    /**
     * 删除消防设施
     */
    @PreAuthorize("@ss.hasPermi('equipment:fighting:remove')")
    @Log(title = "消防设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentFightingService.deleteEquipmentFightingByIds(ids));
    }

    @Log(title = "导入消防设施", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('equipment:fighting:export')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, HttpServletRequest request) throws Exception {
        ExcelUtil<EquipmentFighting> util = new ExcelUtil<>(EquipmentFighting.class);
        List<EquipmentFighting> list = util.importExcel(file.getInputStream());

        String message = equipmentFightingService.importHandler(list, getUsername());
        return AjaxResult.success(message);
    }


    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<EquipmentFighting> util = new ExcelUtil<>(EquipmentFighting.class);
        util.importTemplateExcel(response,"消防设施");
    }
}
